<!--
 * @Descripttion: 审核设置
 * @version: 1.0
 * @Author: 狸猫
 * @Date: 2024-04-11 09:22:08
 * @LastEditors: 狸猫
 * @LastEditTime: 2024-04-15 15:27:58
-->
<template>
  <div class="content">
    <el-descriptions title="审核设置"></el-descriptions>
    <el-form
      :model="form"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <!--      <el-form-item label="签约审核" prop="signingState">-->
      <!--        <el-switch-->
      <!--          v-model="form.signingState"-->
      <!--          active-value="2"-->
      <!--          inactive-value="1"-->
      <!--        ></el-switch>-->
      <!--      </el-form-item>-->
<!--      <div class="tip-text">开启后新提交的签约信息需要审核，旧数据不受影响</div>-->
      <el-form-item label="退租审核" prop="rentingOutState">
        <el-switch
          v-model="form.rentingOutState"
          active-value="2"
          inactive-value="1"
          @change="changeSwitch"
        ></el-switch>
      </el-form-item>
      <div class="tip-text">开启后租客退租需要审核，旧数据不受影响</div>
      <el-form-item label="换房审核" prop="exchangeHouseState">
        <el-switch
          v-model="form.exchangeHouseState"
          active-value="2"
          inactive-value="1"
          @change="changeSwitch"
        ></el-switch>
      </el-form-item>
      <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
      <el-form-item label="转租审核" prop="subleaseState">
        <el-switch
          v-model="form.subleaseState"
          active-value="2"
          inactive-value="1"
          @change="changeSwitch"
        ></el-switch>
      </el-form-item>
      <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
      <el-form-item label="续租审核" prop="continueLeaseState">
        <el-switch
          v-model="form.continueLeaseState"
          active-value="2"
          inactive-value="1"
          @change="changeSwitch"
        ></el-switch>
      </el-form-item>
      <div class="tip-text">开启后租客换房需要审核，旧数据不受影响</div>
<!--      <el-form-item>-->
<!--        <el-button type="primary" @click="putSetting">保存</el-button>-->
<!--      </el-form-item>-->
    </el-form>
  </div>
</template>
<script>
import { orderAuditing, putOrderAuditing } from '@/api/order/order'
import { debounce } from '@/utils'
import { mapGetters } from 'vuex'

export default {
  name: 'checkSet',
  data() {
    return {
      // form: {
      //   tenantId: '',
      //   AUDITING_STATE_OFF: '1',
      //   AUDITING_STATE_ON: '2',
      //   orderAuditingId: 1,
      //   signingState: '1',
      //   rentingOutState: '1',
      //   exchangeHouseState: '1',
      //   subleaseState: '1',
      //   continueLeaseState: '1',
      //   timeOutOffState: '1',
      //   auditing_STATE_OFF: '1',
      //   auditing_STATE_ON: '2'
      // },
      //
      form:{
        tenantId: "",
        orderAuditingId: 1,
        signingState: "1", //签约审核状态： 1关闭 2开启
        rentingOutState: "1", //退租审核状态： 1关闭 2开启
        exchangeHouseState: "1", //换房审核状态： 1关闭 2开启
        subleaseState: "1", //转租审核状态： 1关闭 2开启
        continueLeaseState: "1", //续租审核状态： 1关闭 2开启
        timeOutOffState: "1", //订单超时关闭状态：1关闭 2开启
        auditing_STATE_OFF: "1",
        auditing_STATE_ON: "1"
      }
    }
  },
  computed: {
    ...mapGetters(['enterprises'])
  },
  watch:{
    form:{
      handler(newVal, oldVal){
        console.log(newVal, oldVal)
      },
      deep: true
    }
  },
  created(){
    this.getSetting()
  },
  methods: {
    getSetting() {
      orderAuditing().then((response) => {
        if (response.data) {
          this.form = response.data
        }else{
          this.form['tenantId'] = this.enterprises.tenantId
        }
      })
    },
    changeSwitch(val) {
      this.putSetting()
    },
    putSetting: debounce(function() {
      putOrderAuditing(this.form).then((response) => {
        this.$message.success('保存成功')
      })
    }, 500)
  }
}
</script>
<style lang="scss" scoped>
.content {
  padding: 20px 30px;
}

.tip-text {
  margin-left: 30px;
  font-size: 14px;
  color: #606266;
  font-weight: 500;
  margin-bottom: 30px;
}

::v-deep .el-form-item {
  margin-bottom: 10px;
}
</style>
